# coding=utf-8
'''
Created on 2010-8-8

@author: morningbzy
'''
from sgs.common.constants import colorStr, pointStr

class CardBase(object):
    def __init__(self, id, color, point, cardType):
        self.id = id
        self.color = color
        self.point = point
        self.cardType = cardType
        self.originalCard = [self]

    def action(self, cond, src, args=[]):
        print '%s action!' % self.name

    # affect when user got this card
    def onGot(self, user):
        pass

    # affect when user lose this card
    def onLost(self, user):
        pass

    def setId(self, id):
        self.id = id

    def setOriginalCard(self, cards):
        self.originalCard = cards

    def matchCond(self, condition={}):
        if (condition.has_key('class') and
                    not isinstance(self, condition['class'])):
            return '期望的牌是 [%s]' % condition['class'].name
        elif(condition.has_key('color') and
                        self.color not in condition['color']):
            return '期望的花色是 [%s]' % condition['color']
        elif(condition.has_key('point') and
                        self.point not in condition['point']):
            return '期望的点数是 [%s]' % condition['point']
        else:
            return ''

    def toArray(self):
        color = colorStr[self.color]
        point = pointStr[self.point]
        return [str(self.id), color, point, self.name, str(self.cardType)]

def fakeCardArray(cardId, name):
    #info of a fake card. Has the same format of CardBase.toArray() 
    return [cardId, '', '', name, '']
